/*
 * EditDetails.fx
 *
 * Created on 2009-09-04, 19:20:22
 */

package shmallarchitect.gui;

import javafx.scene.CustomNode;
import javafx.scene.Group;
import javafx.scene.Node;


import javafx.scene.transform.Translate;

import javafx.scene.paint.Color;

import javafx.scene.text.Font;
import javafx.scene.text.Text;

import javafx.scene.control.Button;

import javafx.scene.control.TextBox;

import javafx.scene.shape.Rectangle;
import javafx.scene.input.MouseEvent;

import javafx.scene.control.ListView;

import shmallarchitect.java.Locuma;

import javafx.scene.image.Image;

import javafx.scene.image.ImageView;

import javafx.scene.text.FontWeight;


/**
 * EDIT LOCUM
 */

public var editdetailsmode:Boolean = false;
//public var edits = EditDetails {}

var editedLocum:Locuma; //not created? - not really, no :P
public var resourcelist:Integer[] = [0,0,0];
public var locumbg: Color;

/*
public function edit_locum(locum:BaseLayout.Locuma) {
        editedLocum = locum;
        }*/

var ownersbox:ListView = ListView {
              items: bind for(entry in BaseLayout.owner_list) {entry.getName();
                                                               }
              height: bind 22*sizeof(BaseLayout.owner_list)
              width: 200
              

transforms: [ Translate {x: 420, y: 40 } ]
}

var ost = Text {

        fill: Color.web("#ffffff")
        content: bind "Select owner for this locum: (ID: {ownersbox.selectedIndex} )";

transforms: [ Translate {x: 500, y: 20 } ]

}

var idbox = TextBox {

        text: "";
        columns: 4

transforms: [ Translate {x: 750, y: 60 } ]

}

var idost = Text {

        fill: Color.web("#ffffff")
        content: bind "Resource ID";

transforms: [ Translate {x: 750, y: 50 } ]

}

var resourceinost = Text {

        fill: Color.web("#ffffff")
        content: bind "Resource IDs attached to this Locum: {resourcelist[0]}, {resourcelist[1]}, {resourcelist[2]} ";

transforms: [ Translate {x: 750, y: 20 } ]

}

var i:Integer = 0; // resource local counter

var addresource: Button = Button {
        text: "Add Resource to Locum"
        action: function() {

        if(resourcelist[0] == 0) {i=0}
        else if(resourcelist[1] == 0) {i=1}
        else if(resourcelist[2] == 0) {i=2}

        if (i > 2) { i = 0; }

        resourcelist[i] = java.lang.Integer.parseInt(idbox.text);
        i++;

        }
        transforms: [ Translate {x: 750, y: 90 } ]

}

var removeresource:Text = Text {

      fill: Color.web("#ffffff")
      font: Font.font("Verdana", 10);
      content: "To remove a photo simply click on it. \nPlease wait for the photo to load after adding";

transforms: [ Translate {x: 750, y: 125 } ]

}

var imgurl1:String = bind BaseLayout.resource_list[resourcelist[0]].getUrl();
var imgurl2:String = bind BaseLayout.resource_list[resourcelist[1]].getUrl();
var imgurl3:String = bind BaseLayout.resource_list[resourcelist[2]].getUrl();

public function smallimgs() {


var img1 = bind Image {
                   url: imgurl1;
                   preserveRatio: true
                  }

var img2 = bind Image {
                   url: imgurl2;
                   preserveRatio: true
                  }

var img3 = bind Image {
                   url: imgurl3;
                   preserveRatio: true
                  }

var imgView1 = ImageView {          image: bind img1;
                                    fitWidth: bind ResourceUtil.resize_width(img1, 300)
                                    fitHeight: bind ResourceUtil.resize_height(img1, 150)
                                    preserveRatio: true
                                    smooth: false
                                    cache: false

                                    x: 750
                                    y: 200

                                  onMousePressed: function( e: MouseEvent ):Void {

                                        resourcelist[0] = 0;
                                    }

                                 }

var imgView2 = ImageView {          image: bind img2;
                                    fitWidth: bind ResourceUtil.resize_width(img2, 300)
                                    fitHeight: bind ResourceUtil.resize_height(img2, 150)
                                    preserveRatio: true
                                    smooth: false
                                    cache: false

                                    x: 750
                                    y: 355

                                  onMousePressed: function( e: MouseEvent ):Void {

                                        resourcelist[1] = 0;
                                    }

                                 }


var imgView3 = ImageView {          image: bind img3;
                                    fitWidth: bind ResourceUtil.resize_width(img3, 300)
                                    fitHeight: bind ResourceUtil.resize_height(img3, 150)
                                    preserveRatio: true
                                    smooth: false
                                    cache: false

                                    x: 750
                                    y: 510

                                   onMousePressed: function( e: MouseEvent ):Void {

                                        resourcelist[2] = 0;
                                    }

                                 }

  return Group {
                  content: [

                         imgView1, imgView2, imgView3
                 ]

                 visible: true;
                 transforms: [ Translate {x: 0, y: -50 } ]
                 };

}

public function edit_locum(lo: Locuma):Void {
        editedLocum = lo;
        }

var addtolist: Button = Button {
        text: "Save Locum changes"
        action: function() {

           if(BaseLayout.getLocuma().locumid == 0) {
                    insert 
                        new Locuma(BaseLayout.sequence,sizeof(BaseLayout.local_list),
                            locumbg, namebox.text, descbox.text, wwwbox.text, phonebox.text,
                            ownersbox.selectedIndex, resourcelist)
                    into BaseLayout.local_list;

                    for (k in BaseLayout.sequence) {
                    BaseLayout.board.EditSquare(k, sizeof(BaseLayout.local_list)-1)
                    }

                       }

           else {
                    BaseLayout.local_list[editedLocum.locumid].locumcolor = locumbg;

                    BaseLayout.local_list[editedLocum.locumid].name = namebox.text;
                    BaseLayout.local_list[editedLocum.locumid].textual_desc = descbox.text;
                    BaseLayout.local_list[editedLocum.locumid].www = wwwbox.text;
                    BaseLayout.local_list[editedLocum.locumid].phone = phonebox.text;
                    BaseLayout.local_list[editedLocum.locumid].owner = ownersbox.selectedIndex;
                    BaseLayout.local_list[editedLocum.locumid].setResource(resourcelist);

                    for (k in editedLocum.local_place) {
                    BaseLayout.board.EditSquare(k, editedLocum.locumid)
                    }

        }

                   delete BaseLayout.sequence;
                   resourcelist = [0,0,0];
                   i = 0;

                   BaseLayout.mode = not BaseLayout.mode;
                   EditDetails.editdetailsmode = not EditDetails.editdetailsmode;

        }

        transforms: [ Translate {x: 40, y: 560 } ]
}

// Colorz

var color1: Group = Group {

        content: [
               Rectangle { width: 30 height: 30
                            fill: Color.web("#95bd4f")
                            stroke: Color.web("#555555")
                            strokeWidth: 3
                          }
                 ]

                 transforms: [ Translate {x: 120 y: 480 }]

                         onMousePressed: function( e: MouseEvent ):Void
                         { locumbg = Color.web("#95bd4f")  }
}

var color2: Group = Group {

        content: [
               Rectangle { width: 30 height: 30
                            fill: Color.web("#86b8f6")
                            stroke: Color.web("#555555")
                            strokeWidth: 3
                          }
                 ]

                 transforms: [ Translate {x: 160 y: 480 }]

                         onMousePressed: function( e: MouseEvent ):Void
                         { locumbg = Color.web("#86b8f6")  }
}

var color3: Group = Group {

        content: [
               Rectangle { width: 30 height: 30
                            fill: Color.web("#9dc58c")
                            stroke: Color.web("#555555")
                            strokeWidth: 3
                          }
                 ]

                 transforms: [ Translate {x: 200 y: 480 }]

                         onMousePressed: function( e: MouseEvent ):Void
                         { locumbg = Color.web("#9dc58c")  }
}

 var color4: Group = Group {

        content: [
               Rectangle { width: 30 height: 30
                            fill: Color.web("#e16635")
                            stroke: Color.web("#555555")
                            strokeWidth: 3
                          }
                 ]

                 transforms: [ Translate {x: 120 y: 520 }]

                         onMousePressed: function( e: MouseEvent ):Void
                         { locumbg = Color.web("#e16635")  }
}

var color5: Group = Group {

        content: [
               Rectangle { width: 30 height: 30
                            fill: Color.web("#e877c9")
                            stroke: Color.web("#555555")
                            strokeWidth: 3
                          }
                 ]

                 transforms: [ Translate {x: 160 y: 520 }]

                         onMousePressed: function( e: MouseEvent ):Void
                         { locumbg = Color.web("#e877c9")  }
}

var color6: Group = Group {

        content: [
               Rectangle { width: 30 height: 30
                            fill: Color.web("#eee954")
                            stroke: Color.web("#555555")
                            strokeWidth: 3
                          }
                 ]

                 transforms: [ Translate {x: 200 y: 520 }]

                         onMousePressed: function( e: MouseEvent ):Void
                         { locumbg = Color.web("#eee954")  }
}

var color7: Group = Group {

        content: [
               Rectangle { width: 30 height: 30
                            fill: Color.web("#4da364")
                            stroke: Color.web("#555555")
                            strokeWidth: 3
                          }
                 ]

                 transforms: [ Translate {x: 240 y: 480 }]

                         onMousePressed: function( e: MouseEvent ):Void
                         { locumbg = Color.web("#4da364")  }
}

var color8: Group = Group {

        content: [
               Rectangle { width: 30 height: 30
                            fill: Color.web("#8fd1e9")
                            stroke: Color.web("#555555")
                            strokeWidth: 3
                          }
                 ]

                 transforms: [ Translate {x: 280 y: 480 }]

                         onMousePressed: function( e: MouseEvent ):Void
                         { locumbg = Color.web("#8fd1e9")  }
}

var color9: Group = Group {

        content: [
               Rectangle { width: 30 height: 30
                            fill: Color.web("#9b98f0")
                            stroke: Color.web("#555555")
                            strokeWidth: 3
                          }
                 ]

                 transforms: [ Translate {x: 320 y: 480 }]

                         onMousePressed: function( e: MouseEvent ):Void
                         { locumbg = Color.web("#9b98f0")  }
}

 var color10: Group = Group {

        content: [
               Rectangle { width: 30 height: 30
                            fill: Color.web("#f05f5f")
                            stroke: Color.web("#555555")
                            strokeWidth: 3
                          }
                 ]

                 transforms: [ Translate {x: 240 y: 520 }]

                         onMousePressed: function( e: MouseEvent ):Void
                         { locumbg = Color.web("#f05f5f")  }
}

var color11: Group = Group {

        content: [
               Rectangle { width: 30 height: 30
                            fill: Color.web("#cde7ab")
                            stroke: Color.web("#555555")
                            strokeWidth: 3
                          }
                 ]

                 transforms: [ Translate {x: 280 y: 520 }]

                         onMousePressed: function( e: MouseEvent ):Void
                         { locumbg = Color.web("#cde7ab")  }
}

var color12: Group = Group {

        content: [
               Rectangle { width: 30 height: 30
                            fill: Color.web("#32363a")
                            stroke: Color.web("#555555")
                            strokeWidth: 3
                          }
                 ]

                 transforms: [ Translate {x: 320 y: 520 }]

                         onMousePressed: function( e: MouseEvent ):Void
                         { locumbg = Color.web("#32363a")  }
}


// Colorz end

var currentbg: Rectangle = Rectangle { width: 60 height: 60
                                        fill: bind locumbg;
                                        x: 20, y: 490;
                                     }

var squarelistbox: Text = Text {
              x: 5 y: -2;
              content: bind "SQUARE IDS: {BaseLayout.sequence}"
              font: Font.font("Verdana", 10);
              fill: Color.web("#777777")

transforms: [ Translate {x: 130, y: 0 } ]

};

public var namebox = TextBox {

        text: editedLocum.name;
        columns: 20

transforms: [ Translate {x: 0, y: 30 } ]

}

public var descbox = TextBox {

        text: editedLocum.textual_desc;
        columns: 40

transforms: [ Translate {x: 0, y: 70 } ]

}

public var wwwbox = TextBox {

        text: editedLocum.www;
        columns: 20

transforms: [ Translate {x: 0, y: 110 } ]

}

public var phonebox = TextBox {

        text: editedLocum.phone;
        columns: 20

transforms: [ Translate {x: 0, y: 150 } ]

}

var labels: Group = Group {

content: [

        Text {x: 5 y: -2;
              content: "Locum Name:"
              font: Font.font("Verdana", 12);
              fill: Color.web("#ffffff")
             },

        Text {x: 5 y: -2+40;
              content: "Locum Description:"
              font: Font.font("Verdana", 12);
              fill: Color.web("#ffffff")
             },

        Text {x: 5 y: -2+80;
              content: "Locum WWW:"
              font: Font.font("Verdana", 12);
              fill: Color.web("#ffffff")
             },

        Text {x: 5 y: -2+120;
              content: "Locum Phone:"
              font: Font.font("Verdana", 12);
              fill: Color.web("#ffffff")
             },

        
]

transforms: [ Translate {x: 0, y: 30 } ]

};



 public class EditDetails extends CustomNode {

         public override function create(): Node {
                 return Group {
                         content: [

                                 Text { x: 0 y: 0 // ID po hoverze
                                    font: Font.font("Verdana", 14);
                                    fill: Color.web("#b4b8a2")
                                    content: bind "Details of ID: {editedLocum.locumid}"
                                    },
                                    addtolist, namebox, descbox, wwwbox, phonebox,
                                    squarelistbox, currentbg,
                                    labels, ownersbox, ost, idbox, idost, addresource,
                                    resourceinost, removeresource, smallimgs(),

                                    color1, color2, color3, color4, color5, color6,
                                    color7, color8, color9, color10, color11, color12

                                 ]
                   visible: bind editdetailsmode;
                   transforms: [ Translate {x: 40, y: 80 } ]
                 };
         }
 }


